<template>
	<view class="position">
		
		
		
		<view v-if="isdata">
			<uni-steps :data="logisticsinfo"
			    direction="column" 
			    :active="active">
			</uni-steps>
			
			<view style="height: 100rpx;" v-if="state==='已发货'"></view>
			<view class="bottom" v-if="state==='已发货'">
				<view class="btn" @tap="receiving">
					确定收货
				</view>
			</view>
		</view>
		
		
		<!-- 无订单 -->
		<view v-else class="nodata">
			<view class="fonticon icon">
				&#xe602;
			</view>
			<view class="txt">
				暂无物流信息
			</view>
		</view>
	</view>
</template>

<script>
	import uniSteps from "@/components/uni-steps/uni-steps.vue"
	
	// 接口相关
	import _function from '@/common/_function.js'
	import api from '@/common/api.js'

	export default {
		components: {uniSteps},
		data() {
			return {
				id:'',
				active:0,
				state:'',//订单状态
				logisticsinfo:[], //物流运动轨迹
				orderinfo:'',//订单信息
				isdata:true
			};
		},
		methods:{
			async receiving(){
				const res =  await _function.request(api.receiving,{
					id:this.id
				},'POST')
				if(res.data.code==200){
					uni.showToast({
					    title: res.data.msg,
					    duration: 3000,
						icon:'none'
					})
					setTimeout(()=>{
						uni.navigateBack({
							delta: 1
						})
					},3000)
				}
			}
		},
		
		async onLoad(options) {
			// 订单状态
			this.state = options.state
			
			const res = await _function.request(api.logistics,{
				id:options.id
			},'POST')
			console.log(res)
			if(res.data.code==200){
				// 物流运动轨迹
				this.logisticsinfo = res.data.data.Traces
				this.active = this.logisticsinfo.length-1

				delete res.data.data.Traces
				this.orderinfo = res.data.data
				
				
			}else{
				this.isdata=false
				uni.showToast({
				    title: res.data.msg,
				    duration: 2000,
					icon:'none'
				})
			}
		}
	}
</script>

<style lang="scss">
.position{
	height: 100%;
	.bottom{
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 100rpx;
		padding:0 20rpx;
		box-sizing: border-box;
		display:flex;
		justify-content:center;
		align-items:center;
		.btn{
			height: 70rpx;
			width: 70%;
			background-color: #0081FF;
			color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 10rpx;
		}
	}
	
	.nodata {
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	
		.icon {
			font-size: 80rpx;
		}
	
		.txt {
			font-size: 40rpx;
		}
	}
}	
	
	

</style>
